<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>领用单管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" href="../../css/element-ui.css" />
    <link rel="stylesheet" href="../css/index.css">
    <!--[if lt IE 9]>
    <link rel="stylesheet" href="../css/pages/ie8.css"/>
    <script src="../../js/common/html5shiv.min.js"></script>
    <script src="../../js/common/respond.min.js"></script>
    <script src="../../js/common/es5-shim.min.js"></script>
    <![endif]-->
    <script src="../../js/common/jquery.min.js"></script>
    <script src="../../js/common/browser.min.js"></script>
    <script src="../../js/common/vue.js"></script>
    <script src="../../js/common/element-ui.js"></script>
    <script src="../js/common/common.js"></script>
    <style>
        #pTableFix tr {
            background-color: #eef1f6;
        }
        
        #pTableFix tr th {
            text-align: center
        }
        
        #pTableFix tr th :nth-child(3) {
            width: 18.33%;
        }
        
        #pTableFix tr th :nth-child(4) {
            width: 18.33%;
        }
        
        #pTableFix tr th :nth-child(5) {
            width: 18.33%;
        }
        
        table {
            width: 100%;
            text-align: center
        }
        
        #pTable>tbody>tr {
            border-bottom: 1px solid #ccc;
        }
        
        #pTable>tbody>tr:last-child {
            border: 0;
        }
        
        #pTable>tbody>tr:nth-child(odd) {
            background: #F4F4F4;
        }
        
        #pTable>tbody>tr:hover {
            background: #F4F4F4;
        }
        
        #pTable>tbody>tr table {
            border-left: 1px solid #ccc;
        }
        
        #pTable .parentTD {
            width: 15%;
            line-height: 30px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        
        .chrildTD {
            width: 33%;
            line-height: 30px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>
</head>

<body>
    <div id="wtly" class="container">
        <div class="rj-header">
            <p class="nav">
                <span class="default">您现在所在的位置:</span>
                <span class="direction">{{prams.breadcrumb}}</span>
            </p>
            <div class="search-container">
                <div class="item">
                    <label>确费时间</label>
                    <div class="time-wrapper">
                        <el-date-picker v-model="inputTimeStart" type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="选择起始时间">
                        </el-date-picker>
                    </div>
                    <span>---</span>
                    <div class="time-wrapper">
                        <el-date-picker v-model="inputTimeEnd" type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="选择结束时间">
                        </el-date-picker>
                    </div>
                </div>
                <div class="item">
                    <label>患者姓名：</label>
                    <input type="text" v-model="xm" />
                </div>
                <div class="item">
                    <label>物品名称：</label>
                    <input type="text" v-model="GoodsName" />
                </div>


                <div class="item">
                    <el-button size="small" type="primary" @click="search">查询</el-button>

                    <el-button size="small" type="info" @click="back">返回</el-button>
                </div>
            </div>
        </div>

        <div class="table-wrapper">



            <div>
                <table id='pTableFix' style="width: 100%">
                    <tr>
                        <th style="width: 15%;height: 30px;line-height: 30px" v-for="item in tablefiex">{{item}}</th>
                    </tr>
                </table>
                <div class="table" style="overflow: auto;height: 260px;">
                    <table id='pTable' style="width: 100%">
                        <tr v-for="item in GoodsData">

                            <td class="parentTD">{{item.xm}}</td>
                            <td class="parentTD">{{item.ylkh}}</td>
                            <td class="parentTD">{{item.jzsj}}</td>

                            <td class="parentTD" :colspan="3" style="width: 55%">
                                <table>
                                    <tr v-if="item.goods&&item.goods.length>0" v-for=" list in item.goods">

                                        <td class="chrildTD" :title="list.GoodsName">{{list.GoodsName}}</td>
                                        <td class="chrildTD">{{list.GoodsCode}}</td>
                                        <td class="chrildTD">{{list.num}}</td>
                                    </tr>
                                </table>

                            </td>


                        </tr>

                    </table>

                </div>
                <el-pagination style="text-align: right" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next" :total="total">
                </el-pagination>

            </div>


            <el-table :data="BillData" border style="width: 100%;margin-top: 10px" height="400">
                <el-table-column prop="goodsCode" label="物品代码" align="center">
                </el-table-column>
                <el-table-column prop="goodsName" label="物品名称" align="center" show-overflow-tooltip>
                </el-table-column>

                <el-table-column prop="BoxUnit" label="计量单位" align="center">
                </el-table-column>

                <el-table-column prop="num" label="确费数量" align="center">
                </el-table-column>
                <el-table-column prop="GoodsCount" label="当前库存" align="center">
                </el-table-column>


            </el-table>
        </div>
    </div>
    <script>
        var app = new Vue({
            el: '#wtly',
            data: {
                prams: JSON.parse(GetRequest().param),
                userJS: JSON.parse(localStorage.getItem("userJS")),
                InDeptAccount: JSON.parse(GetRequest().param).InDeptAccount,
                OutDeptAccount: {},
                tablefiex: ['患者姓名', '卡号', '确费时间', '物品名称', '物品代码', '物品数量'],
                isUserJS: localStorage.getItem("userJS") && JSON.parse(localStorage.getItem("userJS")).length > 0 ? true : false,
                inputTimeStart: getDay(-3) + " 00:00:00",
                inputTimeEnd: getDay(0) + " 23:59:59",
                userID: JSON.parse(localStorage.getItem("currentUser")).Ygid,
                ksdm: JSON.parse(localStorage.getItem("deptInfo")).Ksdm,
                DeptAccountID: JSON.parse(localStorage.getItem("deptInfo")).DeptAccountID,
                GoodsName: null,
                xm: null,
                BillData: [],
                GoodsData: [],

                currentPage: 1,
                pageSize: 20,
                total: 0
            },
            created: function() {
                var that = this;
                console.log(JSON.parse(GetRequest().param))

                this.getStockConfirmation();
                this.getStockExpendSummary()

            },

            methods: {

                handleCurrentChange(val) {


                    this.currentPage = val
                    this.getStockConfirmation();
                },

                handleClick: function(o) {
                    window.location.href = "wtlynewbill.html?param=" + encodeURI(JSON.stringify(this.prams)) + '&BillSN=' + o.BillSN + '&OutDept=' + encodeURI(JSON.stringify(this.OutDeptAccount));
                },


                search: function() {
                    this.currentPage = 1;
                    this.total = 0;
                    this.GoodsData = [];
                    this.getStockConfirmation()
                },
                back: function() {
                    parent.showMenuFn()
                    parent.$('#main').empty()
                },
                jumpToNewBill: function() {
                    window.location.href = "wtlynewbill.html?param=" + encodeURI(JSON.stringify(this.prams)) + '&OutDept=' + encodeURI(JSON.stringify(this.OutDeptAccount));
                },
                conditionModel: function(ColumnName, FullString, Oper, Value, Type) {

                    var obj = {
                        "ColumnName": ColumnName,
                        "FullString": FullString,
                        "Oper": Oper,
                        "Value": Value,
                        "Type": Type
                    }
                    return obj;
                },
                conditionsModel: function(Conditions, Type) {
                    var obj = {
                        "Conditions": Conditions,
                        "Type": Type
                    }
                    return obj
                },

                getStockConfirmation: function() {
                    var that = this
                    var arr = [];
                    var condition;
                    var inputTimeStart = typeof this.inputTimeStart == "object" ? this.inputTimeStart.format("yyyy-MM-dd hh:mm:ss") : this.inputTimeStart;
                    var inputTimeEnd = typeof this.inputTimeEnd == "object" ? this.inputTimeEnd.format("yyyy-MM-dd hh:mm:ss") : this.inputTimeEnd
                    if (!inputTimeStart || !inputTimeEnd) {
                        that.$message.error('时间必选！');
                        return false
                    }
                    var StartTime = this.conditionModel("jzsj", null, "MoreOrEqual", inputTimeStart, "DateTime")
                    var EndTime = this.conditionModel("jzsj", null, "Less", inputTimeEnd, "DateTime")
                    var ksdm = this.conditionModel("ksdm", null, "Equal", this.ksdm, "String") //"4121900"

                    var GoodsName = this.conditionModel("GoodsName", null, "Like", "%" + this.GoodsName + "%", "String")
                    var xm = this.conditionModel("xm", null, "Like", "%" + this.xm + "%", "String")
                        //arr = [StartTime, EndTime, ksdm]
                    if (this.GoodsName && this.GoodsName !== " ") {
                        if (this.xm && this.xm !== " ") {
                            arr = [StartTime, EndTime, ksdm, GoodsName, xm]
                        } else {
                            arr = [StartTime, EndTime, ksdm, GoodsName]
                        }
                    } else {
                        if (this.xm && this.xm !== " ") {
                            arr = [StartTime, EndTime, ksdm, xm]
                        } else {
                            arr = [StartTime, EndTime, ksdm]
                        }
                    }

                    condition = this.conditionsModel(arr, "AND")
                    var parms = {
                        className: 'TwoLevelStockManager',
                        method: 'GetStockConfirmation',
                        condition: JSON.stringify(condition),
                        nowPage: this.currentPage,
                        pageSize: this.pageSize
                    }
                    this._fetch(parms).then(function(data) {
                        that.total = data.pageCount
                        that.GoodsData = data.pageTContent
                    })
                },
                getStockExpendSummary: function() {
                    var that = this

                    var parms = {
                        className: 'TwoLevelStockManager',
                        method: 'GetStockExpendSummary',
                        deptAccountID: this.DeptAccountID

                    }
                    this._fetch(parms).then(function(data) {
                        that.BillData = data

                    })
                },
                _fetch: function(parms) {
                    return new Promise(function(resolve, reject) {
                        $.ajax({
                            type: 'POST',
                            url: getRootPath() + '/api/sendPostRequest',
                            headers: {
                                'Accept': 'application/json',
                                'Content-Type': 'application/json'
                            },
                            data: JSON.stringify(parms),
                            success: function(res) {
                                if (res.isSessionInvalidated) {
                                    parent.window.location.href = getRootPath() + 'login.html'
                                }
                                if (res.issuccess == 0) {
                                    var result = res.result.match(/^[ ]*$/) ? res.result : JSON.parse(res.result);
                                    resolve(result)
                                } else {
                                    reject(res.Message);
                                }
                            },
                            error: function(err) {
                                new Error(err)
                            }
                        });
                    });
                }


            }
        })
    </script>
</body>

</html>